package com.navinfo.android.qcniscan.scan;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.SpannableString;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.navinfo.android.qcniscan.scan.view.MyHelpDialog;
import com.navinfo.android.qcniscan.util.FakeR;
import com.navinfo.android.qcniscan.zxing.activity.CaptureActivity;
import com.navinfo.android.qcniscan.zxing.camera.CameraManager;


public class CouponCaptureActivity extends CaptureActivity implements View.OnClickListener,
        OnFailInterface.Capture {

    private static final String TAG = CouponCaptureActivity.class.getSimpleName();
    private static FakeR fakeR;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 向 ScanBaseActivity 传递数据
        captureFail = this;
    }

    public void initView() {
        fakeR = new FakeR(this);
        setContentView(fakeR.getId("layout", "activity_page_coupon"));

        progressBar = (ProgressBar) findViewById(fakeR.getId("id", "coupon_progressBar"));
        //返回页面
        ImageView coupon_arrow = (ImageView) findViewById(fakeR.getId("id", "coupon_arrow"));
        //发卷、兑换名称
        TextView coupon_title = (TextView) findViewById(fakeR.getId("id", "coupon_title"));
        //发卷、兑换扫描框下提示信息
        TextView coupon_message = (TextView) findViewById(fakeR.getId("id", "coupon_message"));
        //发卷、兑换扫描框下点击入力信息
        TextView coupon_input = (TextView) findViewById(fakeR.getId("id", "coupon_input"));

        Intent couponIntent = getIntent();
        String type = couponIntent.getStringExtra("type");
        if ("2".equals(type)){
            SpannableString spanTitle=new SpannableString("兑换");
            SpannableString spanMessage=new SpannableString("将优惠卷二维码放入框内");
            SpannableString spanInput=new SpannableString("输入消费码");
            coupon_title.setText(spanTitle);
            coupon_message.setText(spanMessage);
            coupon_input.setText(spanInput);
        }
        coupon_arrow.setOnClickListener(this);
        coupon_input.setOnClickListener(this);
    }



    @Override
    public void onClick(View v) {
        if (v.getId() == fakeR.getId("id", "coupon_input") ){
            input_vin();
        }else if (v.getId() == fakeR.getId( "id", "coupon_arrow")){
            arrowReturn();
        }
    }

    //点击返回按钮
    public void arrowReturn(){
        Intent intent = new Intent();
        intent.putExtra("CANCEl_RESULT", "arrow");
        setResult(RESULT_CANCELED, intent);
        finish();
    }

    //手工输入控制
    public void input_vin() {
        Intent intent = new Intent();
        intent.putExtra("CANCEl_RESULT", "input");
        setResult(RESULT_CANCELED, intent);
        finish();
    }

    // 处理扫码数据
    public void dealData(String data, String format) {
        Intent intent = new Intent();
        intent.putExtra("SCAN_RESULT", data);
        intent.putExtra("SCAN_RESULT_FORMAT", format);
        setResult(RESULT_OK, intent);
        finish();
    }

    @Override
    public void onFail(int resultCode, String message) {
//        Intent intent = new Intent();
//        intent.putExtra("SCAN_RESULT", data);
//        intent.putExtra("SCAN_RESULT_FORMAT", format);
//        setResult(RESULT_OK, intent);
        finish();
    }


    public void setStatus() {
        initCapture();
    }
}